﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Website/Site1.Master" AutoEventWireup="true" CodeBehind="ViewMyDeal.aspx.cs" Inherits="ChicagoDealsN.Website.ViewMyDeal" %>

<%@ Import Namespace="ChicagoDealsN" %>


<script language="c#" runat="Server">
    
    private int getId()
    {
        return (Session["Userdet"] as DataUser).User_Id; ;
    }
    bool flag = false;

    public void Page_Load(object sender, EventArgs e)
    {
       // if (!IsPostBack)
       
            try
            {
                int userID = getId();
                //string id = Request.QueryString["Deal_Id"];
                //float savings;
                
                BizDeals bd = new BizDeals();

                System.Data.DataTable ret = bd.BLGetDealByUserId(userID);
                if (ret != null)
                {
                    deals.DataSource = ret;
                    deals.DataBind();
                    deals.Visible = true;
                    confirmation.Text = "We've found some deals for you!";
                }
                else { confirmation.Text = "nothing found!"; }
            }    
            catch (Exception ex)
            {
                confirmation.Text = "<h3>Invalid request</h1><br/>" + ex + "<br/><br/>";
            }
        //}
    }

    private bool IsAdmin()
    {
        bool isAdmin = false;
        if (Session["UserDet"] != null)
        {
            DataUser usr = Session["UserDet"] as DataUser;
            return usr.Is_Admin == 0 ? false : true;
        }
        return isAdmin;
    }

    private string CheckIfApproved(int value)
    {
        if (value != 0)
        {
            flag = true;
            return "Yes";
        }
        else
        {
            flag = false;
            return "No";
        }
    }


    private bool IsLoggedIn()
    {
        return (Session["UserDet"] != null) ? true : false;
    }

</script>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder4" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder3" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

<div id="conirmation-container">
       <asp:Label id="confirmation" runat="server" />
       <br/>
</div>

<asp:Repeater id="deals" runat="server" Visible="false" >
    <HeaderTemplate>
        <table border="1" width="100%" class="table-style1" cellpadding="4" cellspacing="0">
        <tr bgcolor="#b0c4de">
        <th>DealId</th>
        <th>Title</th>
        <th>Price</th>
        <th>Description</th>
        <th>Img</th>
        <th>Status</th>
        <th>Edit</th>
           </tr>
    </HeaderTemplate>
    <ItemTemplate>
        <tr bgcolor="#f0f0f0">
            <td><%# DataBinder.Eval(Container.DataItem, "Deal_Id") %></td>
            <td><a href="ViewDeal.aspx?id=<%# DataBinder.Eval(Container.DataItem, "Deal_Id") %>"><%# DataBinder.Eval(Container.DataItem, "Deal_Title") %></a></td>
            <td>$<%# DataBinder.Eval(Container.DataItem, "Deal_Price") %></td>
            <td><%# DataBinder.Eval(Container.DataItem, "Deal_Description") %></td>
            <td><img src="<%# DataBinder.Eval(Container.DataItem, "Img_Path")  %>" alt="dealimg" width="150"/></td>
            <td><%# CheckIfApproved(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "Is_Active")))%></td>
            <td><a href="EditItem.aspx?id= <%# DataBinder.Eval(Container.DataItem, "Deal_Id") %>" />Edit </a>
            </td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>


</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="ContentPlaceHolder2" runat="server">
</asp:Content>
